<template>
  <a-modal
    :title="$t('补打彩票')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    class="customHeight customHeightChild modal_title"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel" :loading="confirmLoading">{{ $t('取消') }}</a-button>
      <a-button type="primary" v-print="'#print1'">{{ $t('打印') }}</a-button>
    </template>
    <div id="print1" ref="print1" style="width: 300px; padding: 10px; box-sizing: border-box">
      <div style="font-size: 16px; padding: 4px 0; color: #000">{{ tenantName }}</div>
      <div style="font-size: 16px; padding: 4px 0; color: #000">
        {{ $t('打印时间') }}：{{ moment().format('YYYY-MM-DD HH:mm:ss') }}
      </div>
      <div style="font-size: 16px; padding: 4px 0; color: #000">{{ $t('机位号') }}：{{ model.machineNo }}</div>
      <div style="font-size: 16px; padding: 4px 0; color: #000">{{ $t('编码') }}：{{ model.deviceId }}</div>
      <div style="font-size: 16px; padding: 4px 0; color: #000">{{ $t('设备') }}：{{ model.gameId_dictText }}</div>
      <div style="font-size: 16px; padding: 4px 0 10px; color: #000">
        {{ $t('票值') }}：{{ model.value + '（' + model.type_dictText + '）' }}
      </div>
      <div id="qrcode" ref="qrcode" style="width: 120px; height: 120px; overflow: hidden"></div>
      <div style="width: 120px; font-size: 15px; text-align: center; padding: 4px 0 8px; color: #000">
        {{ model.lotteryNo }}
      </div>
    </div>
  </a-modal>
</template>
<script>
import { mapGetters } from 'vuex'
import QRCode from 'qrcodejs2'
import moment from 'moment'
import { getAction } from '@/api/manage'

export default {
  name: 'FillModal',
  data() {
    return {
      moment,
      width: 500,
      visible: false,
      confirmLoading: false,
      model: {},
      tenantName: localStorage.getItem('tenantName'),
    }
  },
  methods: {
    ...mapGetters(['nickname', 'avatar']),
    show(record) {
      let that = this
      that.visible = true
      that.model = Object.assign({}, record)
      that.$nextTick(() => {
        that.$refs.qrcode.innerHTML = ''
        getAction('/member/bisMemberLottery/getLotteryQrCode', { id: that.model.id }).then((res) => {
        if (res.success) {
          that.model.lotteryQrCode = res.result
          var qrcode = new QRCode('qrcode', {
            width: 120, //二维码的宽度
            height: 120, //二维码的高度
            text: that.model.lotteryQrCode, //调用weixincode()方法时后台传的code
            colorDark: '#000', //二维码颜色
            colorLight: '#fff', //二维码底色
            correctLevel: QRCode.CorrectLevel.L, //容错率，L/M/H
          })
        } else {
          that.$message.warning(res.message)
        }
      })
      })
      //
      
    },
    handleCancel() {
      this.visible = false
    },
  },
}
</script>
